package cn.wolfcode.luowowo.article.service.impl;

import cn.wolfcode.luowowo.article.domain.Scenic;
import cn.wolfcode.luowowo.article.mapper.ScenicMapper;
import cn.wolfcode.luowowo.article.service.IScenicService;
import com.alibaba.dubbo.config.annotation.Service;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;

@Service
public class ScenicServiceImpl implements IScenicService{

    @Autowired
    private ScenicMapper scenicMapper;

    @Override
    public List<Scenic> getScenicTop5(Long id) {

        List<Scenic> scenicTop5 = scenicMapper.getScenicTop5(id);
        for (Scenic scenic : scenicTop5) {
            List<String> list = scenic.getRelatedSites(); //景点切割集合
            String str = scenic.getNearbyAttractions(); //相关景点

            List<String> top3Img = scenic.getTop3Img(); //图片集合
            String img = scenic.getImg();//图片
            String[] strs = str.split(",");
            for (String s : strs) {
                list.add(s);
            }

            String[] split = img.split(",");
            for (String s : split) {
                top3Img.add(s);
            }
        }
        return scenicTop5;
    }

    @Override
    public Scenic getRemarkById(Long id) {
        Scenic scenic = scenicMapper.selectRemarkById(id);

        List<String> list = scenic.getRelatedSites(); //景点切割集合
        String str = scenic.getNearbyAttractions(); //相关景点

        List<String> top3Img = scenic.getTop3Img(); //图片集合
        String img = scenic.getImg();//图片
        String[] strs = str.split(",");
        for (String s : strs) {
            list.add(s);
        }

        String[] split = img.split(",");
        for (String s : split) {
            top3Img.add(s);
        }

        return scenic;
    }

    /**
     * 修改评论数
     * @param scenic
     */
    @Override
    public void updateCount(Scenic scenic) {
        scenicMapper.updateCount(scenic);
    }

    @Override
    public List<Scenic> selectAll() {

        List<Scenic> selectAll = scenicMapper.selectAll();

        for (Scenic scenic : selectAll) {
            List<String> list = scenic.getRelatedSites(); //景点切割集合
            String str = scenic.getNearbyAttractions(); //相关景点

            List<String> top3Img = scenic.getTop3Img(); //图片集合
            String img = scenic.getImg();//图片
            String[] strs = str.split(",");
            for (String s : strs) {
                list.add(s);
            }

            String[] split = img.split(",");
            for (String s : split) {
                top3Img.add(s);
            }
        }

        return selectAll;
    }

    @Override
    public void goAdd(Scenic scenic) {
        scenicMapper.goAdd(scenic);
    }

    @Override
    public void updateFavorite(Scenic scenic) {
        scenicMapper.updateFavorite(scenic);
    }
}
